package com.ruoyi.hxf.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hxf.domain.Course;
import com.ruoyi.hxf.domain.bo.TypeBo;
import com.ruoyi.hxf.domain.vo.SubjectVo;
import com.ruoyi.hxf.domain.vo.TypeVo;
import com.ruoyi.hxf.mapper.SubjectMapper;
import com.ruoyi.hxf.service.IRosterService;
import com.ruoyi.hxf.service.ITypeService;
import com.ruoyi.system.mapper.SysUserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/class/roster")
public class RosterController extends BaseController {

    private final SysUserMapper sysUserMapper;

    private final SubjectMapper subjectMapper;

    private final IRosterService iRosterService;

    private final ITypeService iTypeService;

    /**
     * 根据课程查询对应的老师
     *
     * @param subjectName 课程名称
     * @return
     */
//    @SaCheckPermission("system:user:query")
    @GetMapping("/subjectName/{subjectName}/{id}/{nodes}/{belongName}")
    public R<List<SysUser>> getInfo(@PathVariable("subjectName") String subjectName, @PathVariable("id") String id, @PathVariable("nodes") String nodes, @PathVariable("belongName") String belongName) {
        List<SysUser> sysUsers = new ArrayList<>();

        if (nodes.equals("1")) {
            sysUsers = sysUserMapper.selectChooseUserAllListOne(subjectName, id, belongName);
        }
        if (nodes.equals("2")) {
            sysUsers = sysUserMapper.selectChooseUserAllListTwo(subjectName, id, belongName);
        }
        if (nodes.equals("3")) {
            sysUsers = sysUserMapper.selectChooseUserAllListThree(subjectName, id, belongName);
        }
        if (nodes.equals("4")) {
            sysUsers = sysUserMapper.selectChooseUserAllListFour(subjectName, id, belongName);
        }
        if (nodes.equals("5")) {
            sysUsers = sysUserMapper.selectChooseUserAllListFive(subjectName, id, belongName);
        }
        if (nodes.equals("6")) {
            sysUsers = sysUserMapper.selectChooseUserAllListSix(subjectName, id, belongName);
        }
//        List<SysUser> sysUsers = sysUserMapper.selectUserAllList(subjectName);
        return R.ok(sysUsers);
    }


    /**
     * 查询课程的列表
     *
     * @return
     */
    @GetMapping("/list")
    public List<SubjectVo> list() {
        return subjectMapper.selectSubjectAllList();
    }

    /**
     * 根据班级ID查询班级的课程表
     *
     * @param classId 班级ID
     * @return
     */
    @GetMapping("/listClassCourse/{classId}")
    public List<Course> listClassCourse(@PathVariable("classId") String classId) {
        return iRosterService.listClassCourse(classId);
    }


    /**
     * 查询班级创建管理列表
     */
//    @SaCheckPermission("class:type:list")
    @GetMapping("/studentClass")
    public R<List<TypeVo>> list(TypeBo bo) {
        bo.setStatus("0");
        List<TypeVo> list = iTypeService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 课表的建立和修改
     *
     * @param course 全部从早到下午的课程
     * @return
     */
    @Log(title = "课程的管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody List<Course> course) {
        return toAjax(iRosterService.insertByBo(course));
    }


    /**
     * 根据班级的ID逻辑删除
     *
     * @param classId 班级ID
     * @return
     */
    @Log(title = "根据班级的ID逻辑删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{classId}")
    public R<Void> remove(@PathVariable("classId") String classId) {
        return toAjax(iRosterService.deleteWithValidByIds(classId));
    }

    //    @SaCheckPermission("system:user:query")
    @GetMapping("/{userId}")
    public R<List<SysUser>> getInfoTeacher(@PathVariable("userId") String userId) {
        List<SysUser> sysUsers = sysUserMapper.getInfoTeacher();
        return R.ok(sysUsers);
    }


}
